package com.kinon.ogt.api.service;

import android.util.Log;

import com.kinon.ogt.api.OgtApi;
import com.kinon.ogt.api.convert.GsonConvertFactory;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * 佛祖保佑 永无BUG
 *
 * @author WangZhiYao
 * @date 2018/4/23
 */
public class ServiceFactory {

    private static final String TAG = "ServiceFactory";

    private static final String HOST_OGT = "https://ogtchain.com";

    private static final long TIME_OUT = 5L;

    private static OkHttpClient mHttpClient = new OkHttpClient.Builder()
            .addInterceptor(new HttpLoggingInterceptor(message -> Log.wtf(TAG, message))
                    .setLevel(HttpLoggingInterceptor.Level.BASIC))
            .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
            .readTimeout(TIME_OUT, TimeUnit.SECONDS)
            .build();

    private static OgtApi mOgtApi = new Retrofit.Builder()
            .baseUrl(HOST_OGT)
            //.addConverterFactory(GsonConverterFactory.create())
            .addConverterFactory(GsonConvertFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(mHttpClient)
            .build()
            .create(OgtApi.class);

    public static OgtApi getOgtApi() {
        return mOgtApi;
    }
}
